<?php

namespace App\Model;

class AudioApi extends BaseModel
{

    public function __construct()
    {

    }


    //珍珠赠送
    public function pearl_recharge($user_id, $pearl_num, $msg)
    {
        $data['user_id'] = $user_id;
        $data['pearl_num'] = $pearl_num;
        $data['msg'] = $msg;
        $pearl_api = json_decode(curl_request(getKkaudioApiUrl() . '/inner/finance/pearl/recharge', $data), true);
        if ($pearl_api['code'] !== 0) {
            //充值失败
            write_log('apiErrorLog', 'pearlApiError', $data);
            return false;
        }
        return true;
    }


    /*
     * 用户赠送商品
     * [@param] $data['user_id']  -- 用户id
     * [@param] $data['goods_id']  -- 商品id
     * [@param] $data['goods_type']  -- 商品类型
     * [@param] $data['time_limit']  -- 赠送时间
     *
     * */
    public function sendUsedMall($data)
    {
        if (empty($data['goods_id']) || empty($data['goods_type']) || empty($data['user_id'])) {
            return false;
        }
        $api = json_decode(curl_request(getKkaudioApiUrl() . '/inner/mall/goods/give_user', $data), true);

        if ($api['code'] !== 0) {
            //充值失败
            $api_data['apiMsg'] = $api['msg'];
            write_log('apiErrorLog', 'sendUsedMallError', $data);
            return false;
        }

        return true;
    }


    /*
     * 发送消息通知
     * [@param] $data['user_id']  -- 用户id
     * [@param] $data['goods_id']  -- 商品id
     * */
    public function sendMsgApi($user_id, $msg)
    {
        $data['user_id'] = $user_id;
        $data['msg'] = $msg;
        $api = curl_request(getKkaudioApiUrl() . '/inner/msg/text', $data);
        if ($api['code'] !== 0) {
            write_log('apiErrorLog', 'sendUsedMallError', $data);
            return false;
        }
        return true;
    }


    /*
   * 发送全服消息通知
   * [@param] $data['user_id']  -- 用户id
   * */
    public function sendAllAppApi($user_id)
    {
        $data['user_id'] = $user_id;
        $api = curl_request(getKkaudioApiUrl() . '/inner/msg/simple_full_service_msg', $data);
        if ($api['code'] !== 0) {
            write_log('apiErrorLog', 'sendUserAllAppError', $data);
            return false;
        }
        return true;
    }


    public function sendRing($user_id, $ring_id, $time)
    {
        $data['user_id'] = $user_id;
        $data['ring_id'] = $ring_id;
        $data['time_limit'] = $time;
        $data['type'] = 1;
        $api = curl_request(getKkaudioApiUrl() . '/inner/coupling/ring_record/create', $data, 'urlencoded', 'GET');
        if ($api['code'] !== 0) {
            write_log('apiErrorLog', 'sendUsedMallError', $data);
            return false;
        }
        return true;
    }



}